package com.iflytek.cosmo.ocr.common.enums;

/**
 * 结果码
 *
 * @author <a href=mailto:ktyi@iflytek.com>伊开堂</a>
 * @date 2019-07-31 18:24
 */
public enum ResultCodeEnum {
    /** 成功 */
    SUCCESS(1, "成功"),
    /** 失败 */
    FAILED(0, "失败"),

    /* ============================= 10xx 通用类 ============================= */
    MISSING_REQUIRED_PARAMS(1001, "缺少必填参数"),
    INVALID_PARAM_TYPE(1002, "参数类型错误"),
    INVALID_PARAM(1003, "参数不合法"),
    FILENAME_TOO_LONG(1004, "文件名长度超过限制"),


    /* ============================= 11xx 引擎类 ============================= */
    /** 发送请求异常 */
    ENGINE_REQUEST_ERROR(1101, "请求引擎失败"),
    /** 无响应 或 响应内容为空 */
    ENGINE_RESULT_EMPTY(1101, "引擎识别结果为空"),
    /** 返回失败响应 */
    ENGINE_RESULT_FAILED(1101, "引擎识别失败"),
    /** 解析响应结果失败 */
    ENGINE_RESULT_PARSE_ERROR(1101, "引擎识别结果解析失败"),

    /* ============================= 12xx FastDFS类 ============================= */
    /** 发送请求异常 */
    FASTDFS_REQUEST_ERROR(1201, "请求FastDFS失败"),

    /* ----------- 123x 上传类 ---------- */
    /** 发送请求异常 */
    FASTDFS_UPLOAD_ERROR(1231, "上传文件到FastDFS失败"),
    /* ----------- 125x 下载类 ---------- */
    /** 无响应 或 响应内容为空 */
    FASTDFS_DOWNLOAD_ERROR(1251, "从FastDFS下载文件失败"),
    /* ----------- 127x 操作类 ---------- */

    /* ============================= 13xx Redis类 ============================= */
    REDIS_SAVE_ERROR(1301, "redis保存失败"),
    RECOGNIZE_PAGE_EXCEED_LIMIT(1303, "识别页码总数超过限制"),


    PDF_REQUIRE_PASSWORD(900, "该PDF文件需要密码"),
    PDF_REQUIRE_PASSWORD_ERROR(901, "PDF文件密码错误"),
    PDF_SPLITE_FAILED(902, "PDF文件拆分失败"),
    PDF_READ_FAILED(903, "PDF文件读取失败"),

    ;

    private Integer code;
    private String desc;

    ResultCodeEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ResultCodeEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }

        for (ResultCodeEnum anEnum : values()) {
            if (anEnum.getCode().equals(code)) {
                return anEnum;
            }
        }

        return null;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }
}